package com.gx.smart.building.ui.inspection.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemTaskRecordLayoutBinding;
import com.gx.smart.lib.http.api.response.PlanTaskAsset;
import com.huishi.gx.ib.grpc.lib.ib.app.plantask.v1.dto.PlanTaskAssetDto;

/**
 * @author xiaosy
 * @create 2020/5/8
 * @Describe 维修详情
 **/
public class TaskRecordAdapter extends BaseAdapter<PlanTaskAsset, TaskRecordAdapter.ViewHolder> {
    public TaskRecordAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_task_record_layout;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemTaskRecordLayoutBinding binding = ItemTaskRecordLayoutBinding.inflate(LayoutInflater.from(mContext),
                (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, PlanTaskAsset item, int position) {
        holder.binding.assetName.setText(item.getAssetName());
        holder.binding.assetCode.setText(item.getAssetCode());
        holder.binding.assetTypeName.setText("资产分类: " + item.getAssetTypeName());
        holder.binding.areaName.setText("所属区域: " + item.getAreaName());
        //状态：1-已处理，2-未处理
        if (item.getHandleStatus() == 2) {
            holder.binding.statusLayout.setVisibility(View.GONE);
        } else {
            holder.binding.statusLayout.setVisibility(View.VISIBLE);
            //巡检/保养状态：1-正常，2-异常
            holder.binding.status.setVisibility(View.VISIBLE);
            if (item.getResultStatus() == 2) {
                holder.binding.status.setText("异常");
                holder.binding.status.setTextColor(mContext.getResources().getColor(R.color.font_color_style_23));
                holder.binding.status.setBackgroundResource(R.drawable.shape_status_red_text_view_background);
                //处理方式：1-已上报故障工单
                if (item.getDealType() == 1) {
                    holder.binding.reportStatus.setVisibility(View.VISIBLE);
                } else {
                    holder.binding.reportStatus.setVisibility(View.GONE);
                }
            } else {
                holder.binding.status.setText("正常");
                holder.binding.status.setTextColor(mContext.getResources().getColor(R.color.font_color_style_24));
                holder.binding.status.setBackgroundResource(R.drawable.shape_status_green_text_view_background);
                holder.binding.reportStatus.setVisibility(View.GONE);
            }
        }
    }

    protected static class ViewHolder extends RecyclerView.ViewHolder {
        private final ItemTaskRecordLayoutBinding binding;

        public ViewHolder(ItemTaskRecordLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
